function main() {
    debugger
    let self = this;
    let pageRenderElement = self.$$root().$parent.$parent.$parent;

    const finishFlag = (self.state.extraParams || {})["cardIds"];
    const cardIds = Object.values(finishFlag);

    let formPartEle = this.$$element("form_part_a5wip8");
    const formRenderEle = formPartEle.$$getRenderElement();

    if (formRenderEle) {
        formRenderEle.onSave().then((res) => {
            if (res && res.result) {
                if (Array.isArray(cardIds) && cardIds.length > 0) {
                    const promises = cardIds.map(cardId => {
                        return insrtVerifyRecord(res.result.t_c09a923bb16440f8a24227d6d58369a3, cardId);
                    });

                    Promise.all(promises)
                        .then((results) => {
                            console.log('所有年检记录成功添加', results);
                            if (window.parent) {
                                window.parent.postMessage(JSON.stringify({
                                    event: "close-dialog",
                                    param: { "XXX": "test" }
                                }), "*");
                            }
                        })
                        .catch((error) => {
                            // 处理任何一个插入失败的情况
                            console.error('年检记录添加失败', error);
                        });
                } else {
                    if (window.parent) {
                        window.parent.postMessage(JSON.stringify({
                            event: "close-dialog",
                            param: { "XXX": "test" }
                        }), "*");
                    }
                }
            }
        });
    }
}

function insrtVerifyRecord(verifyData, cardId) {
    return new Promise((resolve, reject) => {
        api.EXEC_FORMULA("INSERT('t_c09a923bb16440f8a24227d6d58369a3',['verify_time','" + verifyData.date_picker_d6dlm7
            + "','card_id'," + cardId
            + ",'verify_year','" + verifyData.text_input_dx1lhf
            + "','new_verify_flag','" + verifyData.number_input_8oiu80
            + "','verify_human_id'," + verifyData.text_input_4wdm5y
            + ",'verify_human_name'," + verifyData.text_input_9l9oqg
            + ",'verify_opinion'," + verifyData.textarea_azkupv
            + ",'verify_state_id','" + verifyData.radio_fm3wo4
            + "','verify_state_name','" + verifyData.radio_fm3wo4_text + "'])")
            .then((res) => {
                if (res.result) {
                    resolve(res);
                } else {
                    reject(res);
                }
            })
            .catch((error) => {
                reject(error);  // 捕捉到 API 请求的错误
            });
    });
}
